//
//  MysqlDB.h
//  MacTest
//
//  Created by scarlettsun on 12-7-18.
//  Copyright (c) 2012年 tencent. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <mysql.h>

#define USER_NAME @"root"
#define PASS_WORD  @"123456"
#define DATA_BASE  @"MiniMacQQ"
#define SERVER_NAME @"localhost"

NSString * hostIp;
NSString * userName;
NSString * password;
NSString * dbName;

@interface MysqlDB : NSObject {
    MYSQL *myconnect;
}

// connect mysql
-(void)connectHost:(NSString *)host connectUser:(NSString *)user connectPassword:(NSString *)password connectName:(NSString *)name;

// close connection
-(void)disconnect;

// execure query
-(int)query:(NSString *)sql;
-(int)realQuery:(NSString *)sql;

// result sets
-(MYSQL_RES *)storeResult;

// fetchresult sets
-(NSMutableArray *)fetchRow:(MYSQL_RES *)result;
-(NSMutableArray *)fetchAllRows:(MYSQL_RES *)result;

//release result sets
- (void) releaseResult:(MYSQL_RES *) result;

/**insert data 
 success ---- return Id(autoIncrement  col);
 **/
- (NSUInteger) doDataInsert:(NSString * )sql;

/**update da
 success ---- return 0;
  error   ----- not 0;
  **/
- (int) doDataUpdate:(NSString * )sql;

/**delete data 
 success ---- return 0;
 error   ----- not 0;
 **/
- (int) doDataDelete:(NSString * )sql;

/**query data 
 success  ---- return data array list;
 fail ----nil 
 **/
- (NSMutableArray *) doDataQuery:(NSString * )sql ;

/**escape string
 success --- 转义处理数据库特殊字符
 fail --- nil
 
 addBy arvintan 12-8-17
 */
- (NSString *) doEscapeString:(NSString *)str;
@end